package com.lnking.lnkingplace.controller;


import com.lnking.common.http.ReturnResult;
import com.lnking.lnkingplace.model.request.epidemicPrevention.EpidemicPreventionAddRequest;
import com.lnking.lnkingplace.model.request.epidemicPrevention.EpidemicPreventionSearchRequest;
import com.lnking.lnkingplace.model.request.epidemicPrevention.EpidemicPreventionUpdateRequest;
import com.lnking.lnkingplace.model.request.notice.NoticeAddRequest;
import com.lnking.lnkingplace.model.request.notice.NoticeUpdateRequest;
import com.lnking.lnkingplace.model.request.place.PlaceListRequest;
import com.lnking.lnkingplace.service.IEpidemicPreventionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

/**
 * <p>
 * 防疫数据导入 前端控制器
 * </p>
 *
 * @author zhangqt
 * @since 2022-08-20
 */
@RestController
@RequestMapping("/epidemic-prevention")
@Api(tags = "防疫平台数据")
public class EpidemicPreventionController {

    @Resource
    IEpidemicPreventionService epidemicPreventionService;

    @ApiOperation("导出excel")
    @GetMapping(value = "/export")
    public ReturnResult exportExcel(HttpServletResponse response) throws Exception{
        epidemicPreventionService.exportExcel(response);
        return ReturnResult.success();
    }

    @ApiOperation("导入excel")
    @PostMapping(value = "/import")
    public ReturnResult importExcel(@RequestParam("file") MultipartFile file) throws Exception {
        epidemicPreventionService.importExcel(file);
        return ReturnResult.success();
    }

    @GetMapping("list")
    @ApiOperation("查询列表")
    public ReturnResult queryPageList(@Valid EpidemicPreventionSearchRequest placeListRequest){
        return ReturnResult.success(epidemicPreventionService.pageList(placeListRequest));
    }

    @ApiOperation("新增")
    @PostMapping("/add")
    public ReturnResult add(@RequestBody @Valid EpidemicPreventionAddRequest params)throws Exception{
        epidemicPreventionService.add(params);
        return ReturnResult.success();
    }

    @ApiOperation("修改")
    @PostMapping("/update")
    public ReturnResult update(@RequestBody @Valid EpidemicPreventionUpdateRequest params)throws Exception{
        epidemicPreventionService.update(params);
        return ReturnResult.success();
    }

    @ApiOperation("删除")
    @DeleteMapping("/{id}")
    public ReturnResult delete(@PathVariable("id") String id) {
        epidemicPreventionService.removeById(id);
        return ReturnResult.success();
    }

    @ApiOperation("查询详情")
    @GetMapping("get-details")
    public ReturnResult getDetails(String id){
        return ReturnResult.success(epidemicPreventionService.getById(id));
    }
}
